#include "global.h"
#include <string.h>
#include <unistd.h>

#include "easylogger/inc/elog.h"
#include "easylogger/inc/elog_cfg.h"
#include "easylogger/plugins/file/elog_file.h"
#include "easylogger/plugins/file/elog_file_cfg.h"

char g_udp_port[20];
const char* g_ini_file = "config/conf.ini";

/**
 * EasyLogger demo
 */
void test_elog2(void)
{
    int i = 0;
    char* log = "FOR";
    char str[718];
    sprintf(str, "%d %s", i , log);
    elog_file_write(str, strlen(str));
    elog_file_deinit();
}

void read_global2()
{
//    char** value = NULL;
//    int ini_read(g_ini_file, "test_section", "test_key", value);
}

int config_log2(void)
{
    /* close printf buffer */
    /* initialize EasyLogger */
    /* set EasyLogger log format */
    ElogFileCfg cfg;
    cfg.name = "log.log";
    cfg.max_size = 40000;
    cfg.max_rotate = 120;

    elog_file_init();
    elog_file_config(&cfg);
    elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
    elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
    elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
    elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
    elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
    elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
#ifdef ELOG_COLOR_ENABLE
    elog_set_text_color_enabled(true);
#endif
    /* start EasyLogger */
    elog_start();

    /* dynamic set enable or disable for output logs (true or false) */
//    elog_set_output_enabled(false);
    /* dynamic set output logs's level (from ELOG_LVL_ASSERT to ELOG_LVL_VERBOSE) */
//    elog_set_filter_lvl(ELOG_LVL_WARN);
    /* dynamic set output logs's filter for tag */
//    elog_set_filter_tag("main");
    /* dynamic set output logs's filter for keyword */
//    elog_set_filter_kw("Hello");
    /* dynamic set output logs's tag filter */
//    elog_set_filter_tag_lvl("main", ELOG_LVL_WARN);

    /* test logger output */
    test_elog2();

    return 0;
}


